package com.tabview.difficultpoint;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import java.io.File;

/**
 * 作者：zhouXJ on 2016/4/11 15:15
 */
public class OpenFile {

    /**
     * 打开图片
     *
     * @param context
     * @param filePath
     */
    public static void openImg(Context context, String filePath) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(new File(filePath));
        intent.setDataAndType(uri, "image/*");
        context.startActivity(intent);
    }

    /**
     * 打开pdf
     *
     * @param context
     * @param filePath
     */
    public static void openPDF(Context context, String filePath) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(new File(filePath));
        intent.setDataAndType(uri, "application/pdf");
        context.startActivity(intent);
    }

    /**
     * 打开Word
     *
     * @param context
     * @param filePath
     */
    public static void openWord(Context context, String filePath) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(new File(filePath));
        intent.setDataAndType(uri, "application/msword");
        context.startActivity(intent);
    }

    /**
     * 打开PPT
     *
     * @param context
     * @param filePath
     */
    public static void openPPT(Context context, String filePath) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(new File(filePath));
        intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
        context.startActivity(intent);
    }

    /**
     * 打开Excel
     *
     * @param context
     * @param filePath
     */
    public static void openExcel(Context context, String filePath) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(new File(filePath));
        intent.setDataAndType(uri, "application/vnd.ms-excel");
        context.startActivity(intent);
    }
}
